<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<script type="text/javascript" src="js/project.js"></script>
		<script type="text/javascript" src="js/drag_drop.js"></script>
		<link rel="STYLESHEET" href="styles/project.css" type="text/css">
		<link rel="stylesheet" href="styles/control.css" type="text/css"/>
		<%@ include file="../master/head.jsp"%>
		<%@ include file="IsStudent.jsp"%>
	</head>
	<body>
		<div id="container">
			<div id="wrapper">
				<div id="sidebar">
					<div id="sb_top"><%@ include file="../master/sbTop.jsp"%></div>
					<div class="sb_content"><!--##########--> <!-- Start Menu --> <%@ include
		 file="../master/studentMenu.jsp"%> <!-- Profile -->
<%@ include file="../master/profile.jsp"%> <!-- links -->
<%@ include file="../master/links.jsp"%>
						<div class="copyright"><%@ include file="../master/copyright.jsp"%>
						</div>
						
					</div>
				<!-- /sb_content --></div>
				<!-- /sidebar --> <!-- Top -->
				<div id="header"><%@ include file="../master/header.jsp"%>
				</div>
				
				
				<!-- Start main content -->
				<div id="content">
					<div id="intro">
						<div class="intro_t">
							<h1><span>..</span>Welcome to<span>..</span></h1>
							<h2>student project managment system</h2>
							
						</div>
					</div>
                                         <h1>Your Choices</h1>
					<%@ page import="java.sql.*,database.*" %>
					<%
                                        DBCon db = new DBCon();
                                                String control = db.getControlValue("choose_project");
            
            if(control.equals("true"))
            {
try{
						
                                                
		if (db == null) {
			out.print("asd");
		} else {
			ResultSet res1 = db.getSProject((String)session.getAttribute("id"));
			if (res1.next())//print Assigned projects
			{
				out.println("<h2>Your Project is <a href='showProject.jsp?projId=" + res1.getString("ID") + "' >" + res1.getString(2) + "</a></h2>");
			} else //print all projects
			{
				// Execute query and save results.
				res1 = db.getProjectsValidated();
					%>
					<div><a href="myChoiceModern.jsp">Modern Style?</a></div>					
					<%
			}
		}
					%>
					
					<div>
						
						<!-- /intro --> <%@ page import="java.util.*,java.sql.*,database.*"%>
					   
<%
		//Project.ID, Project.Title, Project.Description, Professor.FirstName, Professor.LastName 
		// Execute query and save results.
		ResultSet res = db.getProjectsValidated();
		String[] titlo = new String[40], fn = new String[40], ln = new String[40];
		int proId[] = new int[40];
		for (int j = 0; j < proId.length; j++) {
			if (res.next()) {
				proId[j] = res.getInt("project.ID"); 
				titlo[j] = res.getString("project.Title");
				fn[j] = res.getString("professor.FirstName");
				ln[j] = res.getString("professor.LastName");
			}
		}

		res = db.getProjectsChoosed("WHERE choosedprojects.StudentId=" + (String) session.getAttribute("id") + " AND project.ID = choosedprojects.ProjectId order by priority");
		out.println("<TABLE ID='tabM' ALIGN='CENTER'>");
		int projectId[] = new int[3], i = 0;
		while (res.next()) {
			projectId[i++] = res.getInt("project.ID");
		}
%>

						<tr>
							<td><br />
							</td>
							<td><br />
							</td>
						</tr>
						<form action="changeProject.jsp" method="post">
							
							<tr>
								<td>First Choice</td>
								<td><select name="proj1">
										<%
		for (int j = 0; j < proId.length; j++) {
			if (titlo[j] != null) {
				out.println("<option value='" + proId[j] + "' " + (proId[j] == projectId[0] ? " selected " : "") + " >" + titlo[j] + " Supervised by DR. " + fn[j] + " " + ln[j] + "</option>");
			}
		}
										%>
								</select></td>
							</tr>
							<tr>
								<td>Second Choice</td>
								<td><select name="proj2">
										<%
		for (int j = 0; j < proId.length; j++) {
			if (titlo[j] != null) {
				out.println("<option value='" + proId[j] + "' " + (proId[j] == projectId[1] ? " Selected " : "") + " >" + titlo[j] + " Supervised by DR. " + fn[j] + " " + ln[j] + "</option>");
			}
		}
										%>
								</select></td>
							</tr>
							<tr>
								<td>Third Choice</td>
								<td><select name="proj3">
										<%
		for (int j = 0; j < proId.length; j++) {
			if (titlo[j] != null) {
				out.println("<option value='" + proId[j] + "' " + (proId[j] == projectId[2] ? " Selected " : "") + " >" + titlo[j] + " Supervised by DR. " + fn[j] + " " + ln[j] + "</option>");
			}
		}
		
}
catch(Exception e)
{
    response.sendRedirect("../connectionFailed.jsp?"+e);
}

										%>
								</select></td>
							</tr>
							<tr>
								<td><input type="submit" value="Add Project" name="add" /></td>
								<td><input type="submit" value="Remove All my project Choice"
										   name="remove" /></td>
							</tr>
							
						</form>
						<table></table>
                
                <%   }else
                {%>
                <br/><br/><center><h2> This service is not availabe now </h2></center>
            <%}%>
					</div>
				</div>
			<!-- /content --></div>
			<!-- /wrapper -->
			<div class="clear">&nbsp;</div>
		<!-- Important! Fix the problem of height in Firefox --></div>
		<!-- /Container -->

		
	</body>
</html>